package com.ksm.client.presenter;

import java.util.List;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Panel;
import com.google.inject.Inject;
import com.ksm.client.ManagerEventBus;
import com.ksm.client.document.service.IKsmServiceAsync;
import com.ksm.client.view.MainView;
import com.ksm.transfer.dto.TvaDTO;
import com.ksm.transfer.dto.TypeDocumentDTO;
import com.mvp4g.client.annotation.Presenter;
import com.mvp4g.client.presenter.BasePresenter;

@Presenter(view = MainView.class)
public class MainPresenter extends BasePresenter<MainView, ManagerEventBus> implements IMainPresenter {

	@Inject
	IKsmServiceAsync ksmService;

	public interface IMainView {

		Panel getDocumentPanel();

		void showErrorMessage(String message);

	}

	public void onChangeBody(IsWidget widget) {

	}

	public void onInitApp() {
		ksmService.loadTva(new AsyncCallback<List<TvaDTO>>() {

			@Override
			public void onSuccess(List<TvaDTO> tvaDTOs) {
				getEventBus().referentialTvaUpdate(tvaDTOs);
			}

			@Override
			public void onFailure(Throwable arg0) {
				System.out.println("load tva error" + arg0.getMessage());
			}
		});

		ksmService.loadTypeDocument(new AsyncCallback<List<TypeDocumentDTO>>() {

			@Override
			public void onSuccess(List<TypeDocumentDTO> typeDocumentDTOs) {
				getEventBus().referentialTypeDocumentUpdate(typeDocumentDTOs);
			}

			@Override
			public void onFailure(Throwable arg0) {
				System.out.println("load type document error" + arg0.getMessage());
			}
		});

		getView().asWidget();
	}
}
